﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Client
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void ExitMenuItem_Click(object sender, EventArgs e)
        {
            Application.ExitThread();
            Application.Exit();
        }

        private void AboutMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox about = new AboutBox();
            about.Show(this);
        }

        private void ConnectMenuItem_Click(object sender, EventArgs e)
        {
            Tractor.LoginForm = new LoginForm(this);
            Tractor.LoginForm.Show(this);
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

        private void DisconnectMenuItem_Click(object sender, EventArgs e)
        {
            DisconnectMenuItem.Visible = false;
            ConnectMenuItem.Visible = true;
            AgentPanel.Visible = false;
            LoadingBox.Visible = true;
            this.HideLoadingBox();
        }


        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            this.RenderMapUpdate();
        }

        private void MainForm_SizeChanged(object sender, EventArgs e)
        {
            this.RenderMapUpdate();
        }

        private void RenderMapUpdate()
        {
            if (Tractor.Started && Tractor.Map.Size > 0)
            {
                Tractor.Map.RenderMap();
            }
        }

        public void HideLoadingBox()
        {
            this.LoadingBox.InvokeEx(box => box.Visible = false);
        }

        public void ShowLoadingBox()
        {
            this.LoadingBox.InvokeEx(box => box.Visible = true);
        }

        private void MainForm_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Up: Tractor.MoveUp();
                    break;
                case Keys.Left: Tractor.MoveLeft();
                    break;
                case Keys.Right: Tractor.MoveRight();
                    break;
                case Keys.Down: Tractor.MoveDown();
                    break;
            }

        }

        private void LoadingBox_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            TractorFuel tf = new TractorFuel();
            tf.Show();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            gridPanel = new AStarForm();
            gridPanel.Show();
            
        }

        private void LoadingBox_Click_1(object sender, EventArgs e)
        {

        }

        private void LoadingBox_Click_2(object sender, EventArgs e)
        {

        }

        private void LoadingBox_Click_3(object sender, EventArgs e)
        {

        }
    }
}
